<?php
include_once("db_connect.php");
$postdata = file_get_contents("php://input");
if (isset($postdata) && !empty($postdata)) {
    $request = json_decode($postdata);
    $username = mysqli_real_escape_string($mysqli, trim($request->username));
    $newpassword = mysqli_real_escape_string($mysqli, trim($request->newpassword));
    $phone = trim($request->phone);
    $sqlSelect = "SELECT * FROM login_user WHERE username='$username' AND phone='$phone' || username='$username' OR phone='$phone'";
    $result = $mysqli->query($sqlSelect);
    if ($result) {
        while ($row = $result->fetch_assoc()) {
            if ($row["username"] == $username && $row["phone"] == $phone) {
                $sql = "UPDATE login_user SET password='$newpassword' WHERE username='$username' AND phone='$phone'";
                if ($mysqli->query($sql)) {
                    $data = array('message' => 'success');
                    echo json_encode($data);
                } 
                else {
                    $data = array('message' => 'error');
                    echo json_encode($data);
                }
            }
            else{
                $data = array('message'=> 'error');
                echo json_encode($data);
            }
        }
    } else {
        $data = array('message' => 'GetData Fail');
        echo json_encode($data);
    }
}

?>